using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Globalization;
using MJB.UI.ContentEditor.Document;

namespace MJB.UI.ContentEditor.Converters
{
    /// <summary>
    /// Converts a document reader into a string.
    /// </summary>
    public class DocumentReaderToStringConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// Converts from an IDocumentReader into a string.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            IDocumentReader reader = value as IDocumentReader;
            if(reader == null)
                return String.Empty;

            return Path.GetFileName(reader.FileName);

        }

        /// <summary>
        /// Cannot convert from a string into an IDocumentReader.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new Exception("Cannot convert from a string to an IDocumentReader.");
        }

        #endregion
    }

}
